package com.pet.mapper;

import com.github.pagehelper.Page;
import com.pet.entity.InvitationCollect;
import com.pet.entity.InvitationInformation;
import com.pet.entity.InvitationLike;
import com.pet.entity.InvitationRemark;
import com.pet.pageDto.InvitationPageDTO;
import com.pet.vo.web.InvitationHotVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface InvitationMapper {

    /**
     * 添加帖子
     * @param entity
     */
    @Insert("insert into pet_manage_system.invitation_information" +
            "(invitation_type, invitation_content, create_user, create_time, " +
            "update_user, update_time, title, invitation_images) " +
            "VALUES " +
            "(#{invitationType},#{invitationContent},#{createUser},#{createTime}," +
            "#{updateUser},#{updateTime},#{title},#{invitationImages})")
    void insertInvitationInformation(InvitationInformation entity);


    Page<InvitationInformation> pageQuery(InvitationPageDTO dto);

    /**
     * 修改帖子
     * @param invitationInformation
     */
    void updateInvitation(InvitationInformation invitationInformation);

    /**
     * 删除帖子
     * @param ids
     */
    void deleteInvitationByIds(List<Integer> ids);

    /**
     * 修改帖子点赞数
     */
    @Update("update pet_manage_system.invitation_information set like_number = #{newNumberLike} where id = #{id}")
    void updateInvitationLikeNumber(Integer newNumberLike,Integer id);

    /**
     * 根据id查询帖子信息
     * @param id
     * @return
     */
    @Select("select * from pet_manage_system.invitation_information where id = #{id}")
    InvitationInformation selectInvitationInfoById(Integer id);

    /**
     * 添加点赞用户信息
     * @param currentId
     */
    @Insert("insert into pet_manage_system.invitation_like (user_id, invitation_id) values (#{currentId},#{id})")
    void insertInvitationLikeInfo(Long currentId,Integer id);

    @Delete("delete from pet_manage_system.invitation_like where user_id = #{currentId} and invitation_id = #{id}")
    void deleteInvitationLike(Long currentId ,Integer id);

    /**
     * 收藏帖子
     * @param currentId
     * @param id
     */
    @Insert("insert into pet_manage_system.invitation_collect (user_id, invitation_id) VALUES (#{currentId},#{id})")
    void insertInvitationCollect(Long currentId, Integer id);

    /**
     * 取消收藏帖子
     * @param currentId
     * @param id
     */
    @Delete("delete from pet_manage_system.invitation_collect where id=#{id} and user_id =#{currentId}")
    void deleteInvitationCollect(Long currentId, Integer id);

    /**
     * 根据用户id查询其收藏列表
     * @param currentId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_collect where user_id = #{currentId}")
    List<InvitationCollect> selectInvitationCollectsByUserId(Long currentId);

    @Insert("insert into pet_manage_system.invitation_remark" +
            "( remark, create_time, create_user, invitation_id) " +
            "values " +
            "(#{remark},#{createTime},#{createUser},#{invitationId})")
    void InsertInvitationRemark(InvitationRemark invitationRemark);

    /**
     * 查询是否点赞
     * @param id
     * @param currentId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_like where user_id = #{currentId} and invitation_id =#{id}")
    InvitationLike invitationRemarkUserLikeStatus(Integer id, Long currentId);

    /**
     * 查询是否点赞
     * @param id
     * @param currentId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_collect where user_id = #{currentId} and invitation_id =#{id}")
    InvitationLike invitationRemarkUserCollectStatus(Integer id, Long currentId);

    /**
     * 查询帖子评论
     * @param invitationId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_remark where invitation_id = #{invitationId}")
    List<InvitationRemark> selectInvitationRemark(Integer invitationId);

    @Update("update pet_manage_system.invitation_information set collect_number = #{i} where id = #{id}")
    void updateInvitationCollectNumber(int i, Integer id);

    /**
     * 查询个人喜欢列表
     * @param currentId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_like where user_id = #{currentId}")
    List<InvitationCollect> selectInvitationLikesById(Long currentId);

    /**
     * 查询热门帖子
     * @return
     */
    @Select("SELECT id, title FROM pet_manage_system.invitation_information " +
            "ORDER BY like_number DESC LIMIT 5")
    List<InvitationHotVO> selectInvitationHot();

    /**
     * 查询发表的评论
     * @param currentId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_remark where create_user = #{currentId}")
    List<InvitationRemark> selectInvitationRemarksSel(Long currentId);

    /**
     * 修改发表的评论
     * @param e
     */
    @Select("update pet_manage_system.invitation_remark " +
            "set remark = #{remark},create_user =#{createUser},create_time=#{createTime} " +
            "where id = #{id}")
    void updateInvitationRemarksSelf(InvitationRemark e);

    /**
     * 删除发表的评论
     * @param id
     */
    @Delete("delete from pet_manage_system.invitation_remark where id =#{id}")
    void deleteInvitationRemarksSelf(Integer id);

    /**
     * 根据id查询 收藏列表信息
     * @param invitationId
     * @return
     */
    @Select("select * from pet_manage_system.invitation_collect " +
            "where invitation_id =#{invitationId} and user_id =#{userId}")
    InvitationCollect selectInvitationCollectsById(Integer invitationId,Long userId);

    /**
     * 删除帖子评论
     * @param invitationIds
     */
    void deleteInvitationRemarksByInvitationId(List<Integer> invitationIds);

    /**
     * 删除帖子点赞
     * @param invitationIds
     */
    void deleteInvitationLikeByIds(List<Integer> invitationIds);

    /**
     * 删除帖子收藏
     * @param invitationIds
     */
    void deleteInvitationCollectByIds(List<Integer> invitationIds);

    /**
     * 根据用户id查询帖子信息
     * @param userId
     */
    @Select("select id from pet_manage_system.invitation_information where create_user = #{userId}")
    List<Integer> selectInvitationInfoByUserId(Integer userId);

    @Delete("delete from pet_manage_system.invitation_collect where user_id = #{userId}")
    void deleteInvitationCollectByUserId(Integer userId);

    @Delete("delete from pet_manage_system.invitation_like where user_id = #{userId}")
    void deleteInvitationLikeByUserId(Integer userId);

    @Delete("delete from pet_manage_system.invitation_remark where create_user = #{userId}")
    void deleteInvitationRemarksByUserId(Integer userId);

    @Delete("delete from pet_manage_system.invitation_information where create_user = #{userId}")
    void deleteInvitationByUserId(Integer userId);
}
